package Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Dao.CountTodayInDao;

public class CountTodayInServlet extends HttpServlet {
	
	private CountTodayInDao counttodayindao = new CountTodayInDao();
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		String method = request.getParameter("method");
		String path = "pages/Count_In.jsp";
		boolean ac = false;
		if(method.equals("list")){
			double sum_pay_history = counttodayindao.Sum_Pay_Total();
			double sum_pay_today = counttodayindao.Sum_PayTotal_Today();
			
			double sum_refund_history = counttodayindao.Sum_Refund_Total();
			double sum_refund_today = counttodayindao.Sum_RefundTotal_Today();
			
			int count_pay_history = counttodayindao.Count_PayTotal_History();
			int count_pay_today = counttodayindao.Count_PayTotal_Today();
			
			int count_refund_history = counttodayindao.Countr_RefundTotal_History();
			int count_refund_today = counttodayindao.Count_RefundTotal_Today();
			
			int sel_pay_first_num = counttodayindao.Sel_Pay_Today_Fist_Num();
			int sel_pay_end_num = counttodayindao.Sel_Pay_Today_End_Num();
			int sel_refund_first_num = counttodayindao.Sel_Refund_Today_First_Num();
			int sel_refund_end_num = counttodayindao.Sel_Refund_Today_End_Num();
			request.setAttribute("pay_first_num", sel_pay_first_num);
			request.setAttribute("pay_end_num", sel_pay_end_num);
			request.setAttribute("refund_first_num", sel_refund_first_num);
			request.setAttribute("refund_end_num", sel_refund_end_num);
			
			request.setAttribute("sum_pay_history", sum_pay_history);
			request.setAttribute("sum_refund_history", sum_refund_history);
			request.setAttribute("sum_pay_today", sum_pay_today);
			request.setAttribute("sum_refund_today", sum_refund_today);
			request.setAttribute("count_pay_history", count_pay_history);
			request.setAttribute("count_refund_history", count_refund_history);
			request.setAttribute("count_pay_today", count_pay_today);
			request.setAttribute("count_refund_today", count_refund_today);
		}
		if(ac){
			response.sendRedirect(path);
		}else{
			request.getRequestDispatcher(path).forward(request, response);
		}
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}
}
